package com.example.imtoken.modules.main.wallet.details.trade.details

import android.content.Context
import android.content.Intent
import android.view.View
import com.blankj.utilcode.util.TimeUtils
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseActivity
import com.example.imtoken.databinding.ActivityTransferDetailsBinding
import com.example.imtoken.entitys.http.TransactionsEntityItem
import com.example.imtoken.extend.click
import com.example.imtoken.extend.visibility
import com.example.imtoken.modules.main.wallet.details.trade.details.share.TransferDetailsShareDialogFragment

/**
 * 转账详情
 * @property id Int 转账记录保存id
 */
class TransferDetailsActivity :
    BaseActivity<TransferDetailsViewModel, ActivityTransferDetailsBinding>(TransferDetailsViewModel::class.java) {

    companion object {
        private const val INFO = "info"

        fun gotoActivity(mContext: Context?, info: TransactionsEntityItem) {
            val intent = Intent(mContext, TransferDetailsActivity::class.java)
            intent.putExtra(INFO, info)
            mContext?.startActivity(intent)
        }
    }

    private val info by lazy {
        intent.getParcelableExtra<TransactionsEntityItem>(INFO)
    }


//    private val id by lazy {
//        intent.getIntExtra("id", 0)
//    }

    override fun initLayoutId(): Int {
        return R.layout.activity_transfer_details
    }

    override fun init() {
        initBar(true, R.color.fragment_bg)
        initTitle()
        initClick()

//        viewModel.getData(id)
        initObserve()

        dataBinding.info = info
        val time = (info?.block_at ?: 0) * 1000L
        dataBinding.textView37.text = TimeUtils.millis2String(time)
    }

    private fun initObserve() {
//        viewModel.getTransactionRecordSchema().observe(this) {
//            dataBinding.data = it
//            dataBinding.tvAmount.text = "${it.amount} ${it.coin?.toUpperCase()}"
//            dataBinding.tvGasPrice.text = "${it.gas_price} ${it.coin?.toUpperCase()}"
//        }
    }

    private fun initClick() {
        dataBinding.include12.ivHeadBack.setOnClickListener { this.finish() }

        dataBinding.include12.ivHeadFunction.click {
            info?.let {
                TransferDetailsShareDialogFragment(it).show(
                    supportFragmentManager,
                    "dialog"
                )
            }
        }
    }

    private fun initTitle() {
        dataBinding.include12.clHeadHome.setBackgroundResource(R.color.fragment_bg)
        dataBinding.include12.vLine.visibility = View.INVISIBLE
        dataBinding.include12.tvHeadTitles.text = getString(R.string.details)

        dataBinding.include12.ivHeadFunction.visibility()
        dataBinding.include12.ivHeadFunction.setImageResource(R.mipmap.src_lib_eui_icon_dappshare)
    }
}